package book.intercept;

import Controller.InterceptInterface;
import book.userentity.User;
import intercept.HandlerExecutionChain;
import util.HttpFactory;

public class Intercept implements InterceptInterface {
    public void before() {
        System.out.println("正在登录...");
    }

    public void doFilter(HandlerExecutionChain chain) {
        String url = HttpFactory.getActionFaction().getRequest().getServletPath();
        if(url.equals("/userjudgeLogin")||url.equals("/login.jsp")){
            chain.handler();
        }
        User user=(User)HttpFactory.getActionFaction().getRequest().getServletContext().getAttribute("user");
        if(user!=null){
            chain.handler();
        }
    }

    public void after() {
        System.out.println("登录成功！");
    }
}
